{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "oriented-iceland",
   "metadata": {},
   "source": [
    "https://leetcode.com/problems/toeplitz-matrix\n",
    "\n",
    "\n",
    "Runtime: 88 ms, faster than 43.62% of Python3 online submissions for Toeplitz Matrix.\n",
    "Memory Usage: 14.5 MB, less than 5.53% of Python3 online submissions for Toeplitz Matrix.\n",
    "\n",
    "\n",
    "```python\n",
    "class Solution:\n",
    "    def isToeplitzMatrix(self, matrix: List[List[int]]) -> bool:\n",
    "        #4:10\n",
    "        height = len(matrix)\n",
    "        width = len(matrix[0])\n",
    "        def is_in_matrix(x, y):\n",
    "            if x < width and y < height:\n",
    "                return True\n",
    "            else:\n",
    "                return False\n",
    "        def does_it_OK(start_x, start_y):\n",
    "            #print(start_x, start_y)\n",
    "            if not (is_in_matrix(start_x, start_y)):\n",
    "                return False\n",
    "            else:\n",
    "                value = matrix[start_y][start_x]\n",
    "                while is_in_matrix(start_x+1, start_y+1):\n",
    "                    start_x += 1\n",
    "                    start_y += 1\n",
    "                    if matrix[start_y][start_x] != value:\n",
    "                        return False\n",
    "                return True\n",
    "        for y,_ in enumerate(matrix):\n",
    "            if does_it_OK(0, y) == False:\n",
    "                return False\n",
    "        for x,_ in enumerate(matrix[0]):\n",
    "            if does_it_OK(x, 0) == False:\n",
    "                return False\n",
    "        return True\n",
    "        #4:29\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "immune-employee",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
